﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
namespace BLL
{
    public class AnnounceBLL : IBLL.IAnnounceBLL
    {
        public XElement getNoteFromXml(string path)
        {
            var nxdoc = XDocument.Load(path);

            var result = from key in nxdoc.Descendants("new")
                         where key.Attribute("id").Value == "1"
                         select key;

            return result.First();
        }
        public void writeNoteToXml(string announceTitle, string announceContent)
        {

            string path = @"C:\announce.xml";
            XDocument xdoc = new XDocument(
                  new XProcessingInstruction("xml-stylesheet", "title='EmpInfo'"),
                  new XComment("some comments"),
                  new XElement("Root",
                          new XElement("news",
                                  new XElement("new",
                                          new XAttribute("id", "1"),
                                          new XElement("Name", "admin"),
                                          new XElement("Title", announceTitle),
                                          new XElement("Time", DateTime.Now),
                                          new XElement("Body", announceContent)
                                      )
                              )
                      ),
                  new XComment("more comments")
              );

            xdoc.Save(path);
        }
    }
}
